<template>
  <div class="app-container">
    <!-- 分页查询 -->
    <el-form
      ref="queryParams"
      :model="queryParams"
      size="small"
      label-suffix=":"
      label-position="right"
      label-width="120px"
    >
      <el-row :gutter="10">
        <el-col :span="1.5">
          <el-form-item :label="$t('outboundOrderLang.scratchDate')">
            <el-date-picker
              v-model="queryParams.dateTime"
              type="datetimerange"
              value-format="timestamp"
              :range-separator="$t('to')"
              :start-placeholder="$t('beginDate')"
              :end-placeholder="$t('endDate')"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="1.5">
          <el-form-item>
            <template #label>
              <el-select
                v-model="queryParams.orderType"
                :placeholder="$t('pleaseSelect')"
                @change="changeOrderType"
              >
                <el-option
                  :value="0"
                  :label="$t('outboundOrderLang.logisticsDocumentNumber')"
                />
                <el-option
                  :value="1"
                  :label="$t('outboundOrderLang.providerNo')"
                />
                <el-option :value="2" :label="$t('outboundOrderLang.mixing')" />
              </el-select>
            </template>
            <el-input
              v-model="queryParams.orderNumber"
              type="textarea"
              autosize
              :placeholder="$t('pleaseEnter') + $t('MultipleSpacesSeparated')"
              style="width: 400px"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="1.5">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-search"
            @click="handleQuery"
          >
            {{ $t("query") }}
          </el-button>
          <el-button
            type="primary"
            size="small"
            icon="el-icon-refresh-left"
            @click="handleReset"
          >
            {{ $t("reset") }}
          </el-button>
        </el-col>
      </el-row>
    </el-form>

    <!-- 数据列表 -->
    <el-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      border
      class="mt-10"
    >
      <el-table-column
        :label="$t('tableIndex')"
        type="index"
        :index="indexAdd"
        align="center"
        width="80"
      />
      <el-table-column
        :label="$t('outboundOrderLang.scratchDate')"
        prop="graspingCodeTime"
        align="center"
        min-width="120"
      />
      <el-table-column
        :label="$t('outboundOrderLang.logisticsDocumentNumber')"
        prop="trackingNo"
        align="center"
        min-width="200"
      />
      <el-table-column
        :label="$t('outboundOrderLang.providerNo')"
        prop="providerTrackingNo"
        align="center"
        min-width="160"
      />
      <el-table-column
        :label="$t('outboundOrderLang.orderType')"
        prop="orderVoteTypeName"
        align="center"
        min-width="120"
      >
        <!-- <template slot-scope="scope">
          <span>{{
            $t(
              "statusLang." +
                getTitleByValue(invoicingStatusOptions, scope.row.orderVoteType)
            )
          }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        :label="$t('goodsSKULang.skuNum')"
        prop="skuType"
        align="center"
        min-width="80"
      />
      <el-table-column
        :label="$t('goodsSKULang.skuTotalNum')"
        prop="skuTotalNum"
        align="center"
        min-width="80"
      />
      <el-table-column
        :label="$t('goodsSKULang.customerCode')"
        prop="customerCode"
        align="center"
        min-width="150"
      />
      <el-table-column
        :label="$t('goodsSKULang.operator')"
        prop="graspingCodeUser"
        align="center"
        min-width="150"
      />
    </el-table>

    <!-- 页码 -->
    <el-row type="flex" justify="end" align="middle" style="height: 60px">
      <el-pagination
        :total="total"
        layoout="total,prev,pager,next"
        :current-page="queryParams.pageNo"
        :page-size="queryParams.pageSize"
        @current-change="pageNoChange"
      />
    </el-row>
  </div>
</template>

<script>
import { outboundDateDict, invoicingStatusDict } from '@/utils/dictData'
import { getDictOptionList, getTitleByValue } from '@/utils/dictUtils'
import { queryGraspingCodePageList } from '@/api/business/outboundManage/scratchCode'
export default {
  components: {},
  data() {
    return {
      oderData: [],
      loading: false,
      total: 0,
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        orderType: 0,
        dateTime: [],
        orderNumber: null,
        providerTrackingNo: null, // 物流商单号
        trackingNo: null, // 物流单号
        orderNo: null, // 混合 （TODO）
        graspingCodeTimeStart: null,
        graspingCodeTimeEnd: null
      },
      outboundDateDict: outboundDateDict,
      invoicingStatusDict: invoicingStatusDict,
      getTitleByValue: getTitleByValue,
      invoicingStatusOptions: getDictOptionList(invoicingStatusDict), // 打单类型
      outboundDateOptions: getDictOptionList(outboundDateDict), // 产品状态
      tableData: []
    }
  },
  created() {
    this.queryGraspingCodePageList()
  },

  methods: {
    // 处理时间戳
    handleTimeStamp(dateTime) {
      if (dateTime) {
        const timestamp = dateTime.map((item) => item / 1000)
        this.queryParams.graspingCodeTimeStart = timestamp[0]
        this.queryParams.graspingCodeTimeEnd = timestamp[1]
      }
    },
    // 抓码比对列表
    async queryGraspingCodePageList() {
      this.handleTimeStamp(this.queryParams.dateTime)
      this.changeOrderType(this.queryParams.orderType)
      const { data } = await queryGraspingCodePageList({
        ...this.queryParams
      })
      console.log(data, '抓码比对')
      this.tableData = data.dataList
      this.total = data.totalRowNum
    },
    // 查询
    handleQuery() {
      this.loading = true
      this.queryParams.pageNo = 1
      this.queryGraspingCodePageList()
      this.loading = false
    },
    // 重置
    async handleReset() {
      await this.$refs.queryParams.resetFields()
      this.queryParams = {
        graspingCodeTimeEnd: null,
        graspingCodeTimeStart: null,
        pageNo: 1,
        pageSize: 10,
        orderType: 0,
        dateTime: [],
        orderNumber: null,
        providerTrackingNo: null, // 物流商单号
        trackingNo: null, // 物流单号
        orderNo: null // 混合 （TODO）
      }
      this.queryGraspingCodePageList()
    },
    changeOrderType(val) {
      this.queryParams.orderType = val
      if (this.queryParams.orderType === 0) {
        this.queryParams.trackingNo = this.queryParams.orderNumber
      } else if (this.queryParams.orderType === 1) {
        this.queryParams.providerTrackingNo = this.queryParams.orderNumber
      } else {
        this.queryParams.orderNo = this.queryParams.orderNumber
      }
    },
    cancel() {},
    pageNoChange(newPage) {
      this.queryParams.pageNo = newPage
      this.queryGraspingCodePageList()
    },
    indexAdd(index) {
      const page = this.queryParams.pageNo // 当前页码
      const pagesize = this.queryParams.pageSize // 每页条数
      return index + 1 + (page - 1) * pagesize
    }
  }
}
</script>

<style lang="scss" scoped></style>
